package com.only.common.doucment;


import com.only.common.exception.BizException;

import java.util.Date;
import java.util.Optional;

/**
 * @author only
 * @date 2023/10/17
 * @description
 */
public class DateRange {
    private final Date startTime;
    private final Date endTime;

    public DateRange(Date startTime, Date endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public DateRange(Optional<Date> startTime, Optional<Date> endTime) {
        if (!startTime.isPresent() || !endTime.isPresent()) {
            throw new BizException("", "开始日期或者结束日期不能为空");
        }

        this.startTime = startTime.get();
        this.endTime = endTime.get();
    }

    public static Optional<DateRange> create(Optional<Date> startTime, Optional<Date> endTime) {
        if (!startTime.isPresent() || !endTime.isPresent()) {
            return Optional.empty();
        }

        return Optional.of(new DateRange(startTime, endTime));
    }

    public Date getStartTime() {
        return startTime;
    }

    public Date getEndTime() {
        return endTime;
    }
}
